package gob.osinerg.emergencia.util;


import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;

public class Util {
	
	
	static List lista;
	public static final HashMap MIME_TYPES = new HashMap();
	  static {
	    MIME_TYPES.put("gif", "image/gif");
	    MIME_TYPES.put("jpeg", "image/jpeg");
	    MIME_TYPES.put("jpg", "image/jpeg");
	    MIME_TYPES.put("jpe", "image/jpeg");
	    MIME_TYPES.put("bmp", "image/bmp");
	    MIME_TYPES.put("png", "image/png");
	    MIME_TYPES.put("tif", "image/tiff");
	    MIME_TYPES.put("tiff", "image/tiff");
	    MIME_TYPES.put("jnlp", "application/x-java-jnlp-file");
	    MIME_TYPES.put("js", "application/x-javascript");
	    MIME_TYPES.put("doc", "application/msword");
	    MIME_TYPES.put("bin", "application/octet-stream");
	    MIME_TYPES.put("exe", "application/octet-stream");
	    MIME_TYPES.put("pdf", "application/pdf");
	    MIME_TYPES.put("ai", "application/postscript");
	    MIME_TYPES.put("eps", "application/postscript");
	    MIME_TYPES.put("ps", "application/postscript");
	    MIME_TYPES.put("rtf", "application/rtf");
	    MIME_TYPES.put("class", "application/x-java-vm");
	    MIME_TYPES.put("ser", "application/x-java-serialized-object");
	    MIME_TYPES.put("jar", "application/x-java-archive");
	    MIME_TYPES.put("sh", "application/x-sh");
	    MIME_TYPES.put("tar", "application/x-tar");
	    MIME_TYPES.put("zip", "application/zip");
	    MIME_TYPES.put("ua", "audio/basic");
	    MIME_TYPES.put("wav", "audio/x-wav");
	    MIME_TYPES.put("mid", "audio/x-midi");
	    MIME_TYPES.put("htm", "text/html");
	    MIME_TYPES.put("html", "text/html");
	    MIME_TYPES.put("css", "text/css");
	    MIME_TYPES.put("txt", "text/plain");
	    MIME_TYPES.put("mpeg", "video/mpeg");
	    MIME_TYPES.put("mpg", "video/mpeg");
	    MIME_TYPES.put("mpe", "video/mpeg");
	    MIME_TYPES.put("qt", "video/quicktime");
	    MIME_TYPES.put("mov", "video/quicktime");
	    MIME_TYPES.put("avi", "video/avi");
	    MIME_TYPES.put("movie", "video/x-sgi-movie");
	  }
	  
	  
	  public static void setList(List listax){
		  
		  lista = listax;
	  }
	 public static List getList(){
		 
		return lista; 
	 }

	 
	    /**
	     * Copia un archivo en el sigiente especificado.
	     * El metodo coge la ruta, asigna un nombre y escrive el archivo retornando 
	     * el nomrbe y la ruta del archivo nuevo
	     * @param in InputStream origen
	     * @param ruta ruta destino
	     * @param extension extension que llevara el archivo
	     * @return nombre del nuevo archivo
	     * @throws Exception
	     */
	    public static String copy(InputStream in, String ruta, String nameFile) throws Exception {
	 	   String nombre = ruta +  File.separator + nameFile;
	       OutputStream out = new FileOutputStream(nombre);        
	       byte[] buf = new byte[1024];
	       int len;
	       while ((len = in.read(buf)) > 0) {
	            out.write(buf, 0, len);
	       }
	       in.close();
	       out.close();
	       return nombre;
	    }

}
